<!DOCTYPE html>
<html lang="en" class="yui3-loading">
<head>
    <meta charset="utf-8">
    <title>Using a panel to show a modal form</title>
    <link rel="stylesheet" href="http://yui.yahooapis.com/combo?3.4.0/build/cssreset/reset-min.css&amp;3.4.0/build/cssfonts/fonts-min.css&amp;3.4.0/build/cssbase/base-min.css">
    <script src="../../build/yui/yui-min.js"></script>
</head>
<body class="yui3-skin-sam">


<style type="text/css">
	
#desc {
  margin-bottom:20px;
  border-bottom:1px dotted #333;
}
#desc span {
  background:#a3350d;
  padding:2px;
  color:#f27243;
}

.yui3-panel {
  outline:none;

}

.yui3-panel-content .yui3-widget-hd {
  font-weight:bold;
}

.yui3-panel-content .yui3-widget-bd {
  padding:15px;
}
.yui3-panel-content label {
  margin-right:30px;
}
.yui3-panel-content fieldset {
  border:none;
  padding:0;
}
.yui3-panel-content input[type="text"] {
  border:none;
  border:1px solid #ccc;
  padding: 3px 7px;
  -webkit-border-radius:2px;
  -moz-border-radius:2px;
  border-radius:2px;
  font-size:100%;
  width:200px;
}
#addRow {
  margin-top:10px;
}
</style>
<h1>Using a panel to show a modal form</h1>
<h2>Using a panel to show a modal form</h2>
<div class="yui3-u-1">
<div id="dt"></div>
<p><input type="button" id="addRow" value="Add"></p>

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur non felis dolor. Fusce rutrum velit quis sem luctus ultrices. Vivamus bibendum mollis enim, vel auctor massa convallis accumsan. Curabitur laoreet nunc vel leo laoreet sed feugiat elit tempor. Sed fermentum ligula ut nisi lobortis pretium. Donec ut est at leo rhoncus ultricies eu at nunc. Phasellus semper, lacus ac pulvinar dictum, orci orci iaculis nulla, non condimentum nibh justo eu felis. Nam sed orci a ligula vehicula rutrum. Donec sodales euismod laoreet. Mauris ut augue purus. Nulla porta vehicula ligula, id viverra lacus hendrerit ut. Donec eu est vitae orci ullamcorper pellentesque. Morbi molestie placerat aliquet. Aliquam aliquet consectetur porttitor. Mauris semper tincidunt nisi, in dignissim turpis auctor ac. Sed at enim ligula. Aenean quis dignissim augue.</p>

<p>Nunc quis sem tortor. Quisque lorem quam, auctor sit amet porttitor pretium, accumsan quis arcu. Mauris blandit, enim nec fermentum faucibus, massa lectus posuere massa, eget consequat leo risus in risus. Sed ornare euismod orci sit amet commodo. Suspendisse ultrices dui ut mi venenatis vitae tincidunt dolor pulvinar. Proin at nibh sed libero molestie facilisis. Maecenas magna purus, lacinia eu tempus in, elementum a est. Morbi eget magna sed justo dignissim pulvinar nec vitae justo. Aliquam tincidunt arcu eget orci tempus ornare ullamcorper dolor aliquet. Vestibulum congue posuere porttitor. Pellentesque magna erat, dapibus nec tristique at, posuere sed nisl. In pretium, risus at volutpat pretium, augue nunc commodo metus, vitae ullamcorper risus quam sagittis turpis. Proin eget cursus quam. Sed elit tortor, tempus pharetra lacinia vel, ultrices nec est. Praesent nibh risus, vulputate nec tincidunt eget, lacinia sed eros. Vestibulum vel velit massa. In hac habitasse platea dictumst. Etiam eu magna ligula.</p>

<p>Vivamus vel dui at velit laoreet accumsan. Pellentesque posuere est et urna euismod elementum. Fusce a nibh nisl, vitae iaculis magna. Nulla sit amet odio in elit posuere pellentesque. Nulla sit amet eros eu odio tempus feugiat at vel purus. In vehicula feugiat purus eu ultricies. Aliquam vitae sapien quis augue gravida pretium. Morbi non lectus eu nisi varius mollis. Maecenas eget nisl sit amet turpis cursus gravida at quis odio. Cras viverra eros placerat erat ultricies ultricies.</p>

<p>Aenean malesuada erat vel ipsum iaculis sollicitudin. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed lectus metus, accumsan in molestie vitae, luctus non nibh. Vestibulum rutrum, nulla vel tristique varius, metus nibh tincidunt erat, at mattis turpis justo quis velit. Donec ac lobortis mauris. Nam nulla tellus, placerat sit amet tempus non, consequat sed nibh. Curabitur eget ligula a sem dictum fringilla. Cras fermentum blandit nulla ut vulputate. Nullam iaculis venenatis orci, et tincidunt lorem pellentesque eget. Morbi sit amet nibh id sapien rhoncus mollis. Vestibulum quis neque massa, eget interdum dolor. Donec rhoncus, metus non dignissim imperdiet, nulla orci eleifend sapien, at interdum augue lacus ac quam. Duis ullamcorper, augue eget semper varius, mi nisi rutrum mi, non sagittis neque quam nec ipsum. Curabitur in mauris lacus. Ut porta porttitor nunc, id elementum quam mattis quis. Donec quis libero eros, at malesuada lectus. Cras lectus tellus, pharetra ut tempor ut, fringilla in turpis.</p>

<p>Quisque tempor turpis non ligula ornare cursus. Vivamus tempus lobortis urna sed vestibulum. Duis id ligula eu dolor feugiat laoreet sit amet in enim. Integer ullamcorper erat at sem mattis quis tempor metus ullamcorper. Praesent sed diam elit. Donec vel lorem libero. Suspendisse nec arcu ac purus interdum mollis congue imperdiet erat. Suspendisse eu tristique enim. Quisque volutpat, leo sit amet iaculis luctus, velit neque suscipit nisi, vitae placerat felis diam laoreet metus. Suspendisse consectetur pulvinar commodo. Nulla magna quam, scelerisque blandit pellentesque sed, euismod nec nulla. Curabitur vitae est quis sem condimentum dictum. Aenean tincidunt dolor ac orci consectetur id pulvinar justo aliquam. Proin ante nulla, ullamcorper sit amet auctor in, pulvinar volutpat quam. Sed vitae dolor dui, sed tincidunt nunc. Phasellus euismod consequat fringilla. Quisque semper dolor eget tellus sagittis porta sit amet quis libero.</p>
<div id="panelContent">
    <div class="yui3-widget-bd">
    <form>
      <fieldset>
        <p><label for="id">ID</label><br/>
        <input type="text" name="id" id="productId" placeholder=""></p>
        <p><label for="name">Name</label><br/>
        <input type="text" name="name" id="name" value="" placeholder=""></p>
        <p><label for="password">Price</label><br/>
        <input type="text" name="price" id="price" value="" placeholder="$"></p>
      </fieldset>
      </form>
  </div>
</div>
<div id="nestedPanel"></div>
</div>
<script type="text/javascript">
	YUI().use("datatable-base", "panel", "dd-plugin", function(Y) {


    //Create the datatable with some gadget information
    var cols = ["id","name","price"],
    data = [
        {id:"ga-3475", name:"gadget", price:"$6.99"},
        {id:"sp-9980", name:"sprocket", price:"$3.75"},
        {id:"wi-0650", name:"widget", price:"$4.25"}
    ],
    dt = new Y.DataTable.Base({
        columnset: cols,
        recordset: data,
        summary: "Price sheet for inventory parts",
        caption: "Price sheet for inventory parts"
    }),

    //Create the main modal form
    panel = new Y.Panel({
      srcNode: "#panelContent",
      width: 250,
      centered: true,
      visible: false,
      modal:true,
      zIndex:5,
      headerContent: "Add A New Product",
      plugins: [Y.Plugin.Drag]
    }),

    addRowBtn = Y.one("#addRow"),
    nestedPanel;


    //Render The Datatable
    dt.render("#dt");

    //Add the footer buttons to the modal form
    panel.addButton(
      {
          value: "Add Item",
          action: function(e) { 
            e.preventDefault(); 
            addItem();
          },
          section: Y.WidgetStdMod.FOOTER
      }
    );
    panel.addButton(
      {
          value: "Remove All Items",
          action: function(e) { 
            e.preventDefault(); 
            removeAllItemsConfirm();
          },
          section: Y.WidgetStdMod.FOOTER
      }
    );
    
    //Render the modal form
    panel.render();

    //When the addRowBtn is pressed, show the modal form
    addRowBtn.on('click', function(e) {
      panel.show();
    });

    //Define the addItem function - this will be called 
    //when "Add Item" is pressed on the modal form
    var addItem = function() {
      var o = {}, 
      id = Y.one('#productId'),
      name = Y.one('#name'),
      price = Y.one('#price');

      o.id = id.get("value");
      o.name = name.get("value");
      o.price = price.get("value");

      id.set("value", "");
      name.set("value", "");
      price.set("value", "");


      data.push(o);
      dt.set('recordset', data).render();
      dt.render();
      panel.hide();
    };

    //Define the removeItems function - this will be called 
    //when "Remove All Items" is pressed on the modal form
    //and is confirmed "yes" by the nested panel.
    var removeItems = function() {
      data = [];
      dt.set('recordset', data).render();
      dt.render();
      panel.hide();
    };


    //Instantiate the nested panel if it doesn't exist, otherwise just show it.
    var removeAllItemsConfirm = function() {
      if (!nestedPanel) {
        nestedPanel = new Y.Panel({
          bodyContent: "Are you sure you want to remove all items?",
          zIndex: 6,
          centered:true,
          width:400,
          modal:true,
          buttons: [
            
            {
                value: "Yes",
                action  : function(e) { 
                  e.preventDefault(); 
                  nestedPanel.hide();
                  panel.hide();
                  removeItems();
                },
                section: Y.WidgetStdMod.FOOTER
            },
            {
                value: "No",
                action: function(e) { 
                  e.preventDefault(); 
                  nestedPanel.hide();
                },
                section: Y.WidgetStdMod.FOOTER
            }
          ]
        }).render('#nestedPanel');
      }

      else {
        nestedPanel.show();
      }

    }
});
</script>


</body>
</html>
